package com.tz.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="bs_product")
public class Product implements Serializable{
	
	private static final long serialVersionUID = -1726971534148798455L;

	private long id;
	
	private String name;
	
	private String subName;
	
	private double price;
	
	private double discount;
	
	private double tax;
	
	private String description;
	
	private List<Picture> pictures;
	
	private int stock;
	
	private String detail;
	
	private String color;
	
	private Category category;
	
	public Product() {
		
	}

	public Product(String name, String subName, double price, double discount,
			double tax, String description, List<Picture> pictures, int stock,
			String detail, String color, Category category) {
		super();
		this.name = name;
		this.subName = subName;
		this.price = price;
		this.discount = discount;
		this.tax = tax;
		this.description = description;
		this.pictures = pictures;
		this.stock = stock;
		this.detail = detail;
		this.color = color;
		this.category = category;
	}
	
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSubName() {
		return subName;
	}

	public void setSubName(String subName) {
		this.subName = subName;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public double getDiscount() {
		return discount;
	}

	public void setDiscount(double discount) {
		this.discount = discount;
	}

	public double getTax() {
		return tax;
	}

	public void setTax(double tax) {
		this.tax = tax;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	@OneToMany(fetch=FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	@JoinColumn(name="product_id")
	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}

	public int getStock() {
		return stock;
	}

	public void setStock(int stock) {
		this.stock = stock;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="category_id")
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Product [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", subName=");
		builder.append(subName);
		builder.append(", price=");
		builder.append(price);
		builder.append(", discount=");
		builder.append(discount);
		builder.append(", tax=");
		builder.append(tax);
		builder.append(", description=");
		builder.append(description);
		builder.append(", pictures=");
		builder.append(pictures);
		builder.append(", stock=");
		builder.append(stock);
		builder.append(", detail=");
		builder.append(detail);
		builder.append(", color=");
		builder.append(color);
		builder.append(", category=");
		builder.append(category);
		builder.append("]");
		return builder.toString();
	}
	
	
	

}
